package ogmios.components.templatetags;
import java.io.*;
import java.util.*;
import java.text.*; 
/**
 * A premade tag to print parts of the date
 */
public class DateTag implements TemplateTag
{
 public final String tag;
 public final int datePart;
 /**
 * The numerical day, i.e. 1-31
 */
 public static final int DAY = 0 ;
 /**
 * The name of the month, e.g. January, February, etc.
 */
 public static final int MONTH = 1;
 /**
 * The year, e.g. 2010, 2011, etc.
 */
 public static final int YEAR = 2;
 /**
 * The day of the week, e.g. Sunday, Monday, Tuesday, etc.
 */
 public static final int DAY_OF_WEEK = 3;
 /**
 * The time of day, in 12 hour form. e.g. 12:00 AM
 */
 public static final int TIME = 4; 
 /**
 * Creates a DateTag using {year} as the tag
 */
 public DateTag()
 {
  this("{year}");
 }
 /**
 * Creates a DateTag using YEAR as the datePart
 * @param      tag     The tag that matches with this DateTag
 */
 public DateTag(String tag)
 {
  this(tag, YEAR);
 }
 /**
 * Creates a DateTag
 * @param     tag     The tag that matches with this DateTag
 * @param     datePart     Either DAY, MONTH, YEAR, DAY_OF_WEEK, or TIME
 */
 public DateTag(String tag, int datePart)
 {
  this.tag = tag;
  this.datePart = datePart;
 }
 public String getTag()
 {
  return tag;
 }
 public String getValue(File outputFile)
 {
  return new SimpleDateFormat( 
   datePart == DAY ? "dd" : 
   datePart == MONTH  ? "MMMM" : 
   datePart == YEAR ? "yyyy" :
   datePart == DAY_OF_WEEK ? "EEEE" : 
   "hh:mm aaa"
   ).format(Calendar.getInstance().getTime());
 }
}
